#include "heroplane.h"
#include "config.h"





HeroPlane::HeroPlane()
{
    //初始化加载飞机图片资源
    m_Plane.load(HERO_PATH);

    //初始化飞机坐标
    m_X = (GAME_WIDTH - m_Plane.width()) * 0.5;
    m_Y = GAME_HEIGHT - m_Plane.height();


    //初始化矩形边框
    m_Rect.setWidth(m_Plane.width());
    m_Rect.setHeight(m_Plane.height());
    m_Rect.moveTo(m_X,m_Y);

}


void HeroPlane::setPosition(int x, int y)
{
    m_X = x;
    m_Y = y;
    m_Rect.moveTo(m_X,m_Y);

}

void HeroPlane::shoot()
{
    m_recorder++;

    if(m_recorder < BULLET_INTERVAL)
    {
        return;
    }
    //达到发射时间
    m_recorder = 0;

    //发射子弹123
    for(int i = 0;i < BULLET_NUM;i++)
    {
        //若子弹1空闲则发射
        if(m_bullet[i].m_Free)
        {
            //空闲时间为假
            m_bullet[i].m_Free = false;
            //设置子弹1坐标
            m_bullet[i].m_X = m_X + m_Rect.width() *0.5 + 30;
            m_bullet[i].m_Y = m_Y + 45;
            break;

        }
    }
        for(int i = 0;i < BULLET_NUM;i++)
        {
            //若子弹2空闲则发射
            if(m_bullet[i].m_Free)
            {
                //空闲时间为假
                m_bullet[i].m_Free = false;
                //设置子弹2坐标
                m_bullet[i].m_X = m_X + m_Rect.width() *0.5 - 33;
                m_bullet[i].m_Y = m_Y + 45;
                break;

            }
        }
        for(int i = 0;i < BULLET_NUM;i++)
        {
            //若子弹3空闲则发射
            if(m_bullet[i].m_Free)
            {
                //空闲时间为假
                m_bullet[i].m_Free = false;
                //设置子弹3坐标
                m_bullet[i].m_X = m_X + m_Rect.width() *0.5;
                m_bullet[i].m_Y = m_Y - 30;
                break;

            }
        }
}
